package com.fdb.efp.batch.service.impl;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Vector;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.vfs.FileSystemException;
import org.apache.logging.log4j.ThreadContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import com.baidu.unionloan.common.util.Security;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.basic.framework.core.constant.BaseConstant;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.basic.framework.core.util.DateUtility;
import com.fdb.basic.framework.core.util.SFTPUtil;
import com.fdb.basic.framework.core.util.SpringContextUtils;
import com.fdb.basic.framework.core.util.StringUtil;
import com.fdb.basic.framework.core.util.TraceUtil;
import com.fdb.basic.framework.core.util.ZipUtil;
import com.fdb.basic.sequence.service.facade.SequenceService;
import com.fdb.efp.batch.service.facade.AccFileAnalysisService;
import com.fdb.efp.batch.service.facade.LoanCompensationStatementTotalServiceV2;
import com.fdb.efp.batch.service.util.BaiduFileCyptUtil;
import com.fdb.efp.edoc.service.facade.UpLoadBaiduFileService;
import com.fdb.efp.esb.common.constant.hj.HjConstant;
import com.fdb.efp.esb.service.bo.req.hj.BkkpDtlInf;
import com.fdb.efp.esb.service.bo.req.hj.ReqAccountFundsFreezeBean;
import com.fdb.efp.esb.service.bo.req.hj.ReqBorrowingMoreBean;
import com.fdb.efp.esb.service.bo.req.hj.ReqCompensationBean;
import com.fdb.efp.esb.service.bo.req.hj.ReqUnfreezingAccountFundsBean;
import com.fdb.efp.esb.service.bo.req.hj.ReqVerificationFreezingAndThgBean;
import com.fdb.efp.esb.service.bo.req.hlw.ReqAlarmJudgementBean;
import com.fdb.efp.esb.service.bo.resp.hj.RespAccountFundsFreezeBean;
import com.fdb.efp.esb.service.bo.resp.hj.RespBorrowingMoreBean;
import com.fdb.efp.esb.service.bo.resp.hj.RespUnfreezingAccountFundsBean;
import com.fdb.efp.esb.service.bo.resp.hj.RespVerificationFreezingAndThgBean;
import com.fdb.efp.esb.service.bo.resp.hlw.RespAlarmJudgementBean;
import com.fdb.efp.esb.service.facade.hj.AccountFundsFreezeService;
import com.fdb.efp.esb.service.facade.hj.BorrowingMoreService;
import com.fdb.efp.esb.service.facade.hj.PushCompensationDataService;
import com.fdb.efp.esb.service.facade.hj.UnfreezingAccountFundsService;
import com.fdb.efp.esb.service.facade.hj.VerificationFreezingAndThgService;
import com.fdb.efp.esb.service.facade.hlw.AlarmJudgementService;
import com.fdb.efp.loan.service.facade.FreezFlowBasiService;
import com.fdb.efp.loan.service.facade.LoanAccNoService;
import com.fdb.efp.loan.service.facade.LoanCompensationStatementEnjoyTempService;
import com.fdb.efp.loan.service.facade.LoanCompensationStatementManyiTempService;
import com.fdb.efp.loan.service.facade.LoanCompensationStatementServiceV2;
import com.fdb.efp.loan.service.facade.ReconciliationDocumentsEnjoyTempService;
import com.fdb.efp.loan.service.facade.ReconciliationDocumentsManyiTempService;
import com.fdb.efp.loan.service.facade.ReconciliationDocumentsService;
import com.fdb.efp.loan.service.vo.FreezFlowBasiVo;
import com.fdb.efp.loan.service.vo.LoanAccNoVo;
import com.fdb.efp.loan.service.vo.LoanCompensationStatementEnjoyTempVo;
import com.fdb.efp.loan.service.vo.LoanCompensationStatementManyiTempVo;
import com.fdb.efp.loan.service.vo.LoanCompensationStatementVo;
import com.fdb.efp.loan.service.vo.ReconciliationDocumentsEnjoyTempVo;
import com.fdb.efp.loan.service.vo.ReconciliationDocumentsManyiTempVo;
import com.fdb.efp.loan.service.vo.ReconciliationDocumentsVo;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;

/**
 * 百度代偿日终实现类
 *
 * @author liyakui
 * @version 1.0
 * @since 2019年1月7日 下午8:43:00
 */
@Service("loanCompensationStatementTotalServiceV2")
public class LoanCompensationStatementTotalServiceV2Impl
        implements LoanCompensationStatementTotalServiceV2, AccFileAnalysisService, FrameworkService {

    private final static Logger logger = LoggerFactory.getLogger(LoanCompensationStatementTotalServiceV2Impl.class);
    @Autowired
    @Qualifier("loanCompensationStatementServiceV2")
    private LoanCompensationStatementServiceV2 loanCompensationStatementServiceV2;
    @Autowired
    @Qualifier("loanCompensationStatementManyiTempService")
    private LoanCompensationStatementManyiTempService loanCompensationStatementManyiTempService;
    @Autowired
    @Qualifier("loanCompensationStatementEnjoyTempService")
    private LoanCompensationStatementEnjoyTempService loanCompensationStatementEnjoyTempService;
    @Autowired
    @Qualifier("loanAccNoService")
    private LoanAccNoService loanAccNoService;
    @Autowired
    @Qualifier("borrowingMoreService")
    private BorrowingMoreService borrowingMoreService;
    @Autowired
    @Qualifier("accountFundsFreezeService")
    private AccountFundsFreezeService accountFundsFreezeService;
    @Autowired
    @Qualifier("unfreezingAccountFundsService")
    private UnfreezingAccountFundsService unfreezingAccountFundsService;
    @Autowired
    @Qualifier("verificationFreezingAndThgService")
    private VerificationFreezingAndThgService verificationFreezingAndThgService;
    @Autowired
    @Qualifier("freezFlowBasiService")
    private FreezFlowBasiService freezFlowBasiService;
    @Autowired
    @Qualifier("reconciliationDocumentsService")
    private ReconciliationDocumentsService reconciliationDocumentsService;
    @Autowired
    @Qualifier("reconciliationDocumentsEnjoyTempService")
    private ReconciliationDocumentsEnjoyTempService reconciliationDocumentsEnjoyTempService;
    @Autowired
    @Qualifier("reconciliationDocumentsManyiTempService")
    private ReconciliationDocumentsManyiTempService reconciliationDocumentsManyiTempService;
    @Autowired
    @Qualifier("upLoadBaiduFileService")
    private UpLoadBaiduFileService upLoadBaiduFileService;
    @Autowired
    @Qualifier("alarmJudgementService")
    private AlarmJudgementService alarmJudgementService;

    @Autowired
    @Qualifier("pushCompensationDataService")
    private PushCompensationDataService pushCompensationDataService;

    @Value("${file.remoteDownAccfilePath}")
    private String remoteDownAccfilePath;// 前置文件服务器：下载地址

    @Value("${file.remoteAccfileBakPath}")
    private String remoteAccfileBakPath;// 前置文件服务器：备份地址

    @Value("${analysis.hjFtpHost}")
    private String hjFtpHost;// 前置文件服务器IP地址

    @Value("${analysis.hjUserName}")
    private String hjUserName;// 前置文件服务器用户名

    @Value("${analysis.hjPassword}")
    private String hjPassword;// 前置文件服务器登录密码

    @Value("${analysis.hjFtpPort}")
    private int hjFtpPort;// 前置文件服务器端口号

    @Value("${baiduFile.baiduZxFilePath}")
    private String baiduZxFilePath;// 尊享贷本地下载目录

    @Value("${baiduFile.baiduMyFilePath}")
    private String baiduMyFilePath;// 满易贷本地下载目录

    @Value("${baiduFile.baiduUploadPath}")
    private String baiduUploadPath;// sftp远程路径

    @Value("${baiduFile.institutionCode}")
    private String institutionCode;// 机构码 满易贷 0050

    @Value("${baiduFile.institutionCode2}")
    private String institutionCode2;// 机构码 尊享贷 0051

    @Value("${baiduFile.compensation}")
    private String compensation;// 文件名称

    @Value("${baiduFile.tarGz}")
    private String tarGz;// .tar.gz 文件后缀名

    @Value("${baiduFile.md5}")
    private String md5;// md5 文件后缀名

    @Value("${baiduFile.baiduJm}")
    private String baiduJm;// 解密存放文件夹

    @Value("${baiduFile.baiduJy}")
    private String baiduJy;// 解压文件夹

    @Value("${baiduFile.scrtFlag2}")
    private String scrtFlag2;// 百度代偿标识 baidu2 尊享贷

    @Value("${baiduFile.scrtFlag}")
    private String scrtFlag;// 百度代偿标识 baidu1 满易贷

    @Value("${baiduFile.tarFileName}")
    private String tarFileName;// .tar.gz里面压缩文件名称

    @Value("${baiduFile.usrId}")
    private String usrId;// 用户ID

    @Value("${baiduFile.getPublicKeyPartner}")
    private String getPublicKeyPartner;// 对方公钥

    @Value("${baiduFile.getPrivateKeyLocal}")
    private String getPrivateKeyLocal;// 我方私钥

    // 百度代偿明细文件
    @Value("${baiduFile.compensationItemFileName}")
    private String compensationItem;

    // 百度代偿总账文件
    @Value("${baiduFile.compensationLedgerFileName}")
    private String compensationLedger;
    /** 日志服务*/
    private String msgTemplate = "message{}";
    /** 总账代号*/
    private int MAINTRANSAMT_INDEX = 6;
    /** 前置流水号代码*/
    private final String PRE_SERIAL_NUMBER = "PRE_SERIAL_NUMBER";
    /** 网贷系统英文编码*/
    private final String INTERNET_LOAN_SYSTEM_ID = "OCM";
    /** 网贷系统编号*/
    private final String INTERNET_LOAN_SYSTEM_NUMBER = "2003000";
    /** 百度代偿编码*/
    private final String BAIDUCOMPENSATION = "BDDC";
    /** */
    /**
     *
     * 百度代偿清单尊享文件下载
     *
     * @return
     * @author liyakui
     * @since 2019年1月14日 上午10:12:10
     * @version 1.0
     */
    @Override
    public boolean receiveEnjoyFile(String time) {
        boolean result = true;
        boolean flag = false;
        boolean flag2 = false;
        try {
            // // 获取昨天的日期
            // Calendar calendar = Calendar.getInstance();
            // calendar.add(calendar.DATE, -1);
            // Date time = calendar.getTime();
            String fileName = time + "_" + compensation + "_" + institutionCode2;// 文件名称(无后缀)
            String localFileMd5 = baiduZxFilePath + fileName + md5; // 具体到文件名
            String remoteFileMd5 = baiduUploadPath + fileName + md5;// 具体到文件名
            String localFileTar = baiduZxFilePath + fileName + tarGz; // 具体到文件名
            String remoteFileTar = baiduUploadPath + fileName + tarGz;// 具体到文件名
            String baiduJmPath = baiduZxFilePath + baiduJm;// 解密输出目录
            String baiduJyFileName = tarFileName + tarGz;// 解压文件名
            String baiduJyPath = baiduZxFilePath;// 解压输出目录

            logger.info("下载百度代偿尊享贷文件开始...");
            // 判断文件是否存在，存在则删除后再下载
            String[] filePaths = { localFileMd5, localFileTar, baiduZxFilePath + baiduJyFileName, baiduZxFilePath + "key" };
            for (int i = 0; i < filePaths.length; i++) {
                String filePath = filePaths[i];
                File file = new File(filePath);
                if (file.exists()) {
                    file.delete();
                }
            }
            // 百度代偿文件下载
            flag = BaiduFileCyptUtil.baiduDownFile(remoteFileMd5, localFileMd5, scrtFlag2);
            flag2 = BaiduFileCyptUtil.baiduDownFile(remoteFileTar, localFileTar, scrtFlag2);
            if (flag && flag2) {
                logger.info("下载百度代偿尊享贷文件结束！百度代偿尊享贷文件开始解密...");
                try {
                    // 百度代偿清单文件解密
                    BaiduFileCyptUtil.decryptFile(new File(localFileTar), new File(localFileMd5), baiduJmPath, baiduJyFileName,
                            getPrivateKeyLocal, getPublicKeyPartner);
                } catch (Exception e) {
                    result = false;
                    e.printStackTrace();
                    // 解密文件失败，则告警
                    String msg = "百度代偿尊享贷文件解密出现异常，异常信息：" + e.getMessage();
                    logger.error(msg);
                    ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                    reqAlarmJudgementBean.setAlrmInf(msg);
                    try {
                        getrespAlarmJudgementBean(reqAlarmJudgementBean);
                    } catch (Exception alarme) {
                        alarme.printStackTrace();
                        logger.debug("调用告警接口异常！" + alarme.getMessage());
                    }
                }

                // 创建目录
                String[] urls = { baiduJy, "/" + DateUtility.format10To8(time) };
                for (String url : urls) {
                    baiduJyPath = baiduJyPath + url;
                    File dir = new File(baiduJyPath);
                    if (!dir.exists()) {
                        dir.mkdir();
                    }
                }
                if (result) {
                    logger.info("百度代偿尊享贷文件解密结束！百度代偿尊享贷文件开始解压...");
                    try {
                        // 百度代偿文件解压
                        Security.doUnTarGZip(baiduJmPath, baiduJyPath, baiduJyFileName);
                    } catch (Exception e) {
                        result = false;
                        e.printStackTrace();
                        // 解密文件失败，则告警
                        String msg = "百度代偿尊享贷文件解压出现异常，异常信息：" + e.getMessage();
                        logger.error(msg);
                        ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                        reqAlarmJudgementBean.setAlrmInf(msg);
                        try {
                            getrespAlarmJudgementBean(reqAlarmJudgementBean);
                        } catch (Exception alarme) {
                            alarme.printStackTrace();
                            logger.debug("调用告警接口异常！" + alarme.getMessage());
                        }
                    }
                    logger.info("百度代偿尊享贷文件解压结束！");
                }

                if (result) {
                    logger.info("百度代偿尊享贷文件检查代偿文件是否存在开始！");
                    result = sendCompensationFileErrorMsg(baiduJyPath, "Enjoy");
                    logger.info("百度代偿尊享贷文件检查代偿文件是否存在结束！");
                }
            }
        } catch (Exception e) {
            // 下载文件失败，则告警
            String msg = "百度代偿尊享贷文件下载出现异常，异常信息：" + e.getMessage();
            logger.error(msg);
            ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
            reqAlarmJudgementBean.setAlrmInf(msg);
            try {
                getrespAlarmJudgementBean(reqAlarmJudgementBean);
            } catch (Exception alarme) {
                alarme.printStackTrace();
                logger.debug("调用告警接口异常！" + alarme.getMessage());
            }
            result = false;
            e.printStackTrace();
            logger.error("百度代偿尊享贷文件下载异常！" + e.getMessage());
        }
        return result;
    }

    /**
     * 百度代偿清单满易文件下载
     *
     * @return
     * @author liyakui
     * @version 1.0
     * @since 2019年1月14日 上午10:12:10
     */
    @Override
    public boolean receiveManyiFile(String time) {
        boolean flag = false;
        boolean flag2 = false;
        try {
            // 获取昨天的日期
            // Calendar calendar = Calendar.getInstance();
            // calendar.add(calendar.DATE, -1);
            // Date time = calendar.getTime();
            String fileName = time + "_" + compensation + "_" + institutionCode;// 文件名称(无后缀)
            String localFileMd5 = baiduMyFilePath + fileName + md5; // 具体到文件名
            String remoteFileMd5 = baiduUploadPath + fileName + md5;// 具体到文件名
            String localFileTar = baiduMyFilePath + fileName + tarGz; // 具体到文件名
            String remoteFileTar = baiduUploadPath + fileName + tarGz;// 具体到文件名
            String baiduJmPath = baiduMyFilePath + baiduJm;// 解密输出目录
            String baiduJyFileName = tarFileName + tarGz;// 解压文件名
            String baiduJyPath = baiduMyFilePath;// 解压输出目录

            // 判断文件是否存在，存在则删除后再下载
            String[] filePaths = { localFileMd5, localFileTar, baiduMyFilePath + baiduJyFileName, baiduMyFilePath + "key" };
            for (int i = 0; i < filePaths.length; i++) {
                String filePath = filePaths[i];
                File file = new File(filePath);
                if (file.exists()) {
                    file.delete();
                }
            }
            // 百度代偿文件下载
            logger.info("百度代偿满易贷文件开始下载...");
            flag = BaiduFileCyptUtil.baiduDownFile(remoteFileMd5, localFileMd5, scrtFlag);
            flag2 = BaiduFileCyptUtil.baiduDownFile(remoteFileTar, localFileTar, scrtFlag);
            if (flag && flag2) {
                logger.info("百度代偿满易贷文件下载结束！百度代偿满易贷开始解密...");
                try {
                    // 百度代偿清单文件解密
                    BaiduFileCyptUtil.decryptFile(new File(localFileTar), new File(localFileMd5), baiduJmPath, baiduJyFileName,
                            getPrivateKeyLocal, getPublicKeyPartner);
                } catch (Exception e) {
                    flag = false;
                    e.printStackTrace();
                    // 解密文件失败，则告警
                    String msg = "百度代偿满易贷文件解密出现异常，异常信息：" + e.getMessage();
                    logger.error(msg);
                    ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                    reqAlarmJudgementBean.setAlrmInf(msg);
                    try {
                        getrespAlarmJudgementBean(reqAlarmJudgementBean);
                    } catch (Exception alarme) {
                        alarme.printStackTrace();
                        logger.debug("调用告警接口异常！" + alarme.getMessage());
                    }
                }
                // 创建目录
                String[] urls = { baiduJy, "/" + DateUtility.format10To8(time) };
                for (String url : urls) {
                    baiduJyPath = baiduJyPath + url;
                    File dir = new File(baiduJyPath);
                    if (!dir.exists()) {
                        dir.mkdir();
                    }
                }
                if (flag) {
                    logger.info("百度代偿满易贷文件解密结束！百度代偿满易贷解压开始...");
                    try {
                        // 百度代偿文件解压
                        Security.doUnTarGZip(baiduJmPath, baiduJyPath, baiduJyFileName);
                    } catch (Exception e) {
                        flag = false;
                        e.printStackTrace();
                        // 解密文件失败，则告警
                        String msg = "百度代偿满易贷文件解压出现异常，异常信息：" + e.getMessage();
                        logger.error(msg);
                        ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                        reqAlarmJudgementBean.setAlrmInf(msg);
                        try {
                            getrespAlarmJudgementBean(reqAlarmJudgementBean);
                        } catch (Exception alarme) {
                            alarme.printStackTrace();
                            logger.debug("调用告警接口异常！" + alarme.getMessage());
                        }
                    }
                    logger.info("百度代偿满易贷文件解压结束！");
                }

                if (flag) {
                    logger.info("百度代偿满易贷文件检查代偿文件是否存在开始！");
                    flag = sendCompensationFileErrorMsg(baiduJyPath, "Manyi");
                    logger.info("百度代偿满易贷文件检查代偿文件是否存在结束！");
                }
            }
        } catch (Exception e) {
            // 下载文件失败，则告警
            String msg = "百度代偿满易贷文件下载出现异常，异常信息：" + e.getMessage();
            logger.error(msg);
            ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
            reqAlarmJudgementBean.setAlrmInf(msg);
            try {
                getrespAlarmJudgementBean(reqAlarmJudgementBean);
            } catch (Exception alarme) {
                alarme.printStackTrace();
                logger.debug("调用告警接口异常！" + alarme.getMessage());
            }
            flag = false;
            e.printStackTrace();
            logger.debug("百度代偿满易贷文件下载解密异常！" + e.getMessage());
        }
        return flag;
    }

    /**
     * 百度代偿文件上传影像系统
     *
     * @return
     * @author liyakui
     * @version 1.0
     * @since 2019年1月26日 上午11:02:43
     */
    @Override
    public boolean downAndUploadImageSys() {
        boolean flag = false;
        try {
            String fileName = new SimpleDateFormat("yyyy-MM-dd").format((new Date())) + "_" + compensation + "_" + institutionCode;// 文件名称(无后缀)
            String filePath = baiduMyFilePath + "\\" + baiduJy + fileName;// 解压输出目录 TODO
            SequenceService sequenceService = (SequenceService) SpringContextUtils.getBean("dbSeqService");
            String applySeq = sequenceService.getSequence("ADV_BOOK_NO", null, null);
            upLoadBaiduFileService.uploadBaiduFile(applySeq, filePath);
            flag = true;
        } catch (Exception e) {
            logger.debug("下载和上传百度代偿清单异常！");

        }
        return flag;
    }

    /**
     *
     * 百度代偿装载数据
     *
     * @return
     * @author liyakui
     * @since 2019年1月26日 下午6:08:11
     * @version 1.0
     */
    @Override
    public boolean bathInsert(String batchDate) {
        boolean flag = true;
		// 校验跑批批次日期为空时，直接返回，不执行后续跑批逻辑
		if (checkBatchDateIsNullorBlank(batchDate, "百度代偿装载数据")) {
			flag = false;
			return flag;
		}
        try {
            // 批量新增百度代偿正式表清单
            logger.info("百度代偿文件明细正式表装载开始...");
            bathInsertLoanCompensationStatement(batchDate);
            logger.info("百度代偿文件明细正式表装载结束!百度代偿文件汇总正式表装载开始...");
            // 新增代偿汇总数据
            insertReconciliationDocuments(batchDate);
            logger.info("百度代偿文件汇总正式表装载结束！百度代偿汇总金额校验开始...");
            // 校验各类金额
            checkPrinBal(batchDate);
            logger.info("百度代偿汇总金额校验结束!");
        } catch (DuplicateKeyException e) {
            flag = false;
            logger.debug("装载入库借据号重复！" + e.getMessage());
            // 调告警接口
            ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
            reqAlarmJudgementBean.setAlrmInf("百度代偿装载入库借据号重复！");
            try {
                getrespAlarmJudgementBean(reqAlarmJudgementBean);
            } catch (Exception e1) {
                logger.info("调用告警接口异常！" + e1.getMessage());
            }
        } catch (Exception e) {
            // 调告警接口
            ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
            reqAlarmJudgementBean.setAlrmInf("百度代偿装载出现异常：" + e.getMessage());
            try {
                getrespAlarmJudgementBean(reqAlarmJudgementBean);
            } catch (Exception e1) {
                logger.info("调用告警接口异常！" + e1.getMessage());
            }
            flag = false;
            logger.debug("装载入库异常！" + e.getMessage());
        }
        return flag;
    }

    /**
     * 百度代偿调用账户解冻接口
     *
     * @param
     * @return
     * @throws Exception
     * @author liyakui
     * @version 1.0
     * @since 2019年1月5日 下午3:58:24
     */

    @Override
    public boolean callRespUnfreezingAccountFundsBean(String batchDate) {
        boolean flag = false;
		// 校验跑批批次日期为空时，直接返回，不执行后续跑批逻辑
		if (checkBatchDateIsNullorBlank(batchDate, "百度代偿调用账户解冻接口")) {
			return flag;
		}
        boolean result = false;
        RespUnfreezingAccountFundsBean respUnfreezingAccountFundsBean = null;
        ReqUnfreezingAccountFundsBean reqUnfreezingAccountFundsBean = new ReqUnfreezingAccountFundsBean();
        try {
            // 全局流水号
            SequenceService sequenceService = (SequenceService) SpringContextUtils.getBean("dbSeqService");
            String baiduSeq = sequenceService.getSequence("BAIDU_SEQ", null, null);
            String traceId = "2003" + "002" + new SimpleDateFormat("yyMMddHHmmss").format((new Date())) + baiduSeq;
            ThreadContext.put(TraceUtil.TRACEID, traceId);
            TraceUtil.setTraceId(traceId);
            // 根据日期查询本地正式表批量代偿清单
            LoanCompensationStatementVo intLoanCompensationStatementVo = new LoanCompensationStatementVo();
            intLoanCompensationStatementVo.setCreateTime(batchDate);// 设置当前日期
            List<LoanCompensationStatementVo> list = loanCompensationStatementServiceV2
                    .queryLoanCompensationStatementByDate(intLoanCompensationStatementVo);
            if (list != null && list.size() > 0) {
                // 设置请求bean的值
                List<Object> list2 = getReqUnfreezingAccountFundsBean(reqUnfreezingAccountFundsBean);
                boolean flag2 = (boolean) list2.get(1);
                // 判断冻结查证是否成功,成功则调用解冻接口
                if (flag2) {
                    reqUnfreezingAccountFundsBean = (ReqUnfreezingAccountFundsBean) list2.get(0);
                    respUnfreezingAccountFundsBean = unfreezingAccountFundsService.unfreezingAccountFunds(reqUnfreezingAccountFundsBean);
                    if ("0000".equals(respUnfreezingAccountFundsBean.getWrongCd())) {
                        // 解冻接口成功
                        flag = true;
                        logger.info("调用解冻接口成功！返回结果：" + respUnfreezingAccountFundsBean.toString());
                    } else if ("9903".equals(respUnfreezingAccountFundsBean.getWrongCd())) {
                        // 解冻失败（未冻结解冻失败，备注：老核心错误码有可能会重复！）
                        flag = true;
                        logger.info("调用解冻接口成功(未冻结解冻失败情况)！返回结果：" + respUnfreezingAccountFundsBean.toString());
                    } else {
                        // 解冻接口失败 告警
                        // 调用颖风写的告警判断服务
                        ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                        reqAlarmJudgementBean.setAlrmInf("百度代偿调用账户解冻接口失败！");
                        getrespAlarmJudgementBean(reqAlarmJudgementBean);
                    }
                }

            } else {
                logger.info("百度代偿没有代偿数据...");
                flag = true;
            }
        } catch (Exception e) {
            result = true;
            logger.debug("调用账户解冻接口异常！" + e.getMessage());

        }
        if (result) {
            // 如果调用冻结接口异常或超时，则调用冻结查证接口
            RespVerificationFreezingAndThgBean respVerificationFreezingAndThgBean = new RespVerificationFreezingAndThgBean();
            try {
                respVerificationFreezingAndThgBean = getVerificationFreezingAndThg(respVerificationFreezingAndThgBean, "1", 0);// 1为冻结
            } catch (Exception e) {
                e.printStackTrace();
                logger.debug("调用冻结查证接口异常！" + e.getMessage());
            }

            if ("0000".equals(respVerificationFreezingAndThgBean.getWrongCd())) {
                logger.info("调用冻结查证接口成功！返回结果：" + respVerificationFreezingAndThgBean.toString());
                // 调用冻结查证接口成功，则说明已经冻结成功，还需要解冻
                try {
                    respUnfreezingAccountFundsBean = unfreezingAccountFundsService.unfreezingAccountFunds(reqUnfreezingAccountFundsBean);
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.debug("调用解冻接口异常！" + e.getMessage());
                }
                if ("0000".equals(respUnfreezingAccountFundsBean.getWrongCd())) {
                    // 解冻接口成功
                    flag = true;
                    logger.info("调用解冻接口成功！返回结果：" + respUnfreezingAccountFundsBean.toString());
                } else if ("9903".equals(respUnfreezingAccountFundsBean.getWrongCd())) {
                    // 解冻失败（未冻结解冻失败）TODO
                    flag = true;
                    logger.info("调用解冻接口成功(未冻结解冻失败情况)！返回结果：" + respUnfreezingAccountFundsBean.toString());
                } else {
                    // 解冻接口失败 告警
                    // 调用颖风写的告警判断服务
                    ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                    reqAlarmJudgementBean.setAlrmInf("百度代偿调用账户解冻接口失败！");
                    try {
                        getrespAlarmJudgementBean(reqAlarmJudgementBean);
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger.debug("调用告警接口异常！" + e.getMessage());
                    }
                }
            } else {
                // 调用冻结查证失败，则告警
                logger.info("调用冻结查证失败！返回结果：" + respUnfreezingAccountFundsBean);
                ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                reqAlarmJudgementBean.setAlrmInf("百度代偿调用冻结查证接口失败！");
                try {
                    getrespAlarmJudgementBean(reqAlarmJudgementBean);
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.debug("调用告警接口异常！" + e.getMessage());
                }

            }

        }
        TraceUtil.clear();

        return flag;
    }

    /**
     *
     * 百度代偿划扣调多借多贷接口
     *
     * @return
     * @author liyakui
     * @since 2019年1月4日 下午5:16:44
     * @version 1.0
     */
    @Override
    public boolean callBorrowingMore(String batchDate) {
        RespBorrowingMoreBean respBorrowingMoreBean = null;
        boolean flag = false;
		// 校验跑批批次日期为空时，直接返回，不执行后续跑批逻辑
		if (checkBatchDateIsNullorBlank(batchDate, "百度代偿划扣调多借多贷接口")) {
			return flag;
		}
        boolean result = false;
        List<LoanCompensationStatementVo> listTemp1 = null;
        try {
            // 全局流水号
            SequenceService sequenceService = (SequenceService) SpringContextUtils.getBean("dbSeqService");
            String baiduSeq = sequenceService.getSequence("BAIDU_SEQ", null, null);
            String traceId = "2003" + "002" + new SimpleDateFormat("yyMMddHHmmss").format((new Date())) + baiduSeq;
            ThreadContext.put(TraceUtil.TRACEID, traceId);
            TraceUtil.setTraceId(traceId);

            // 根据日期查询本地正式表批量代偿清单
            LoanCompensationStatementVo intLoanCompensationStatementVo = new LoanCompensationStatementVo();
            intLoanCompensationStatementVo.setCreateTime(batchDate);// 设置当前日期
            listTemp1 = loanCompensationStatementServiceV2.queryLoanCompensationStatementByDate(intLoanCompensationStatementVo);
            if (listTemp1 != null && listTemp1.size() > 0) {
                // 解冻成功，调用多借多贷接口
                respBorrowingMoreBean = getRespBorrowingMoreBean(respBorrowingMoreBean,batchDate);
                if ("0000".equals(respBorrowingMoreBean.getWrongCd())) {
                    // 如果多借多贷返回成功
                    for (LoanCompensationStatementVo loanCompensationStatementVo : listTemp1) {
                        loanCompensationStatementVo.setCompensationSts(BaseConstant.COMPENSATION_STS_03);// 代偿成功
                        // 更新百度代偿清单代偿状态
                        loanCompensationStatementServiceV2.updateByBillNo(loanCompensationStatementVo);
                    }
                    flag = true;
                } else {
                    // 多借多贷返回失败
                    for (LoanCompensationStatementVo loanCompensationStatementVo : listTemp1) {
                        loanCompensationStatementVo.setCompensationSts(BaseConstant.COMPENSATION_STS_02);// 代偿失败
                        // 更新百度代偿清单代偿状态
                        loanCompensationStatementServiceV2.updateByBillNo(loanCompensationStatementVo);
                    }
                    // 告警
                    // 调用颖风写的告警判断服务
                    ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                    reqAlarmJudgementBean.setAlrmInf("百度代偿调用多借多贷接口失败！");
                    getrespAlarmJudgementBean(reqAlarmJudgementBean);
                }

            } else {
                // 当天百度代偿文件没有数据,不调用多借多贷接口,默认多借多贷批次成功
                logger.debug("当天百度代偿文件没有数据");
                flag = true;
            }
        } catch (Exception e) {
            result = true;
            e.printStackTrace();
            logger.debug("调用多借多接口出现异常！" + e.getMessage());

        }
        if (result) {
            // 多借多贷返回异常
            for (LoanCompensationStatementVo loanCompensationStatementVo : listTemp1) {
                loanCompensationStatementVo.setCompensationSts(BaseConstant.COMPENSATION_STS_04);// 代偿状态处理中
                // 更新百度代偿清单代偿状态
                loanCompensationStatementServiceV2.updateByBillNo(loanCompensationStatementVo);
            }
            // 告警
            // 调用颖风写的告警判断服务
            ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
            reqAlarmJudgementBean.setAlrmInf("百度代偿调用多借多贷接口异常！");
            try {
                getrespAlarmJudgementBean(reqAlarmJudgementBean);
            } catch (Exception e) {
                e.printStackTrace();
                logger.debug("调用告警接口异常！" + e.getMessage());
            }
        }
        TraceUtil.clear();
        return flag;
    }

    /**
     *
     * 百度逾期代偿调用账户冻结接口
     *
     * @return
     * @throws Exception
     * @author liyakui
     * @since 2019年1月5日 下午3:57:24
     * @version 1.0
     */
    @Override
    public boolean callRespAccountFundsFreezeBean(String batchDate) {
        RespAccountFundsFreezeBean respAccountFundsFreezeBean = null;
        boolean flag = false;
		// 校验跑批批次日期为空时，直接返回，不执行后续跑批逻辑
		if (checkBatchDateIsNullorBlank(batchDate, "百度逾期代偿调用账户冻结接口")) {
			return flag;
		}
        boolean result = false;
        String advBookNo = null;
        try {
            // 全局流水号
            SequenceService sequenceService = (SequenceService) SpringContextUtils.getBean("dbSeqService");
            String baiduSeq = sequenceService.getSequence("BAIDU_SEQ", null, null);
            advBookNo = sequenceService.getSequence("ADV_BOOK_NO", null, null);
            logger.debug("冻结开始，生成的序列通知书流水号为：" + advBookNo + "***************");
            String traceId = "2003" + "002" + new SimpleDateFormat("yyMMddHHmmss").format((new Date())) + baiduSeq;
            ThreadContext.put(TraceUtil.TRACEID, traceId);
            TraceUtil.setTraceId(traceId);

            // 根据日期查询本地正式表批量代偿清单
            LoanCompensationStatementVo intLoanCompensationStatementVo = new LoanCompensationStatementVo();
            intLoanCompensationStatementVo.setCreateTime(batchDate);// 设置当前日期
            List<LoanCompensationStatementVo> list = loanCompensationStatementServiceV2
                    .queryLoanCompensationStatementByDate(intLoanCompensationStatementVo);
            if (list != null && list.size() > 0) {
                ReqAccountFundsFreezeBean reqAccountFundsFreezeBean = new ReqAccountFundsFreezeBean();
                // 查询保证金账户
                LoanAccNoVo loanAccNoVo = new LoanAccNoVo();
                List<LoanAccNoVo> loanAccNoVos = loanAccNoService.queryLoanAccNo(loanAccNoVo);
                String accLoanNo = null;
                for (LoanAccNoVo loanAccNoVo2 : loanAccNoVos) {
                    if ("A".equals(loanAccNoVo2.getAcconutType())) {
                        accLoanNo = loanAccNoVo2.getAccountNo();
                    }
                }
                reqAccountFundsFreezeBean.setTxnVrty("MS2024");// 交易类型，可不输，不校验
                reqAccountFundsFreezeBean.setFrzCorpCd("10");// 冻结单位，根据业务类型定义，默认是10其他
                reqAccountFundsFreezeBean.setAdvBookTp("");// 通知书类别，非必输
                reqAccountFundsFreezeBean.setAdvBookNo(advBookNo);// 通知书号，非必输
                reqAccountFundsFreezeBean.setAcctNo(accLoanNo);// 账号，西安春禾的保证金账号
                reqAccountFundsFreezeBean.setFrzRsnCd("");// 冻结原因，非必输
                reqAccountFundsFreezeBean.setFrzTp("03");// 冻结类型，3-只进不出
                reqAccountFundsFreezeBean.setFrzAmt("");// 冻结金额，不送
                reqAccountFundsFreezeBean.setFrzMatureDt("");// 冻结到期日，没有则不送
                reqAccountFundsFreezeBean.setSmyRmk("");//// 摘要
                reqAccountFundsFreezeBean.setAuthUsrNo("");// 授权用户，非必输
                reqAccountFundsFreezeBean.setPrevDt(DateUtility.format10To8(DateUtility.getCurrAppDateStr()));// 前置日期，非必输
                reqAccountFundsFreezeBean.setPrevFlowNo("");// 前置流水号，非必输
                reqAccountFundsFreezeBean.setPrevSysNo(INTERNET_LOAN_SYSTEM_ID);// 前置系统编号，非必输
                reqAccountFundsFreezeBean.setBizCd(BAIDUCOMPENSATION);// 业务代码，非必输
                reqAccountFundsFreezeBean.setUsrID(usrId);// 用户ID
                respAccountFundsFreezeBean = accountFundsFreezeService.accountFundsFreeze(reqAccountFundsFreezeBean);

                if ("0000".equals(respAccountFundsFreezeBean.getWrongCd())) {
                    logger.debug("调用冻结接口成功，更新流水配置表开始...");
                    // 账户冻结接口调用成功！更新冻结水流配置表
                    FreezFlowBasiVo freezFlowBasiVo = new FreezFlowBasiVo();
                    freezFlowBasiVo.setOriSts("N");// 更新投产状态为N
                    freezFlowBasiVo.setAdvBookNo(advBookNo);// 通知书号
                    freezFlowBasiVo.setOriFrzDt(null);
                    freezFlowBasiVo.setOriFrzFlowNo(null);
                    freezFlowBasiService.updateFreezFlowBasi(freezFlowBasiVo);
                    logger.debug("调用冻结接口成功，更新流水配置表结束！");
                    flag = true;
                } else {
                    // 告警
                    // 调用颖风写的告警判断服务
                    ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                    reqAlarmJudgementBean.setAlrmInf("百度代偿调用账户冻结接口失败！");
                    getrespAlarmJudgementBean(reqAlarmJudgementBean);
                }
            } else {
                logger.info("百度代偿没有代偿数据...");
                flag = true;
            }
        } catch (Exception e) {
            // 异常或者超时调冻结查证接口
            result = true;
            logger.debug("冻结接口异常！" + e.getMessage());
        }
        if (result) {
            // 调用冻结查证接口
            RespVerificationFreezingAndThgBean respVerificationFreezingAndThgBean = new RespVerificationFreezingAndThgBean();
            try {
                respVerificationFreezingAndThgBean = getVerificationFreezingAndThg(respVerificationFreezingAndThgBean, "1", 0);
            } catch (Exception e) {
                e.printStackTrace();
                logger.debug("调用冻结查证接口异常！" + e.getMessage());
            }
            if ("0000".equals(respVerificationFreezingAndThgBean.getWrongCd())) {
                // 冻结查证接口成功，则冻结接口成功
                // 更新冻结水流配置表
                logger.debug("调用冻结查证接口成功，则表明冻结成功，更新流水配置表开始...");
                FreezFlowBasiVo freezFlowBasiVo = new FreezFlowBasiVo();
                freezFlowBasiVo.setOriSts("N");// 更新投产状态为N
                freezFlowBasiVo.setAdvBookNo(advBookNo);// 通知书号
                freezFlowBasiVo.setOriFrzDt(null);
                freezFlowBasiVo.setOriFrzFlowNo(null);
                try {
                    freezFlowBasiService.updateFreezFlowBasi(freezFlowBasiVo);
                    logger.debug("调用冻结查证接口成功，则表明冻结成功，更新流水配置表结束！");
                } catch (Exception e) {
                    logger.debug("更新流水配置异常！");
                }
                flag = true;
            } else {
                // 查证接口失败
                // 告警
                // 调用颖风写的告警判断服务
                ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                reqAlarmJudgementBean.setAlrmInf("百度代偿调用账户冻结接口异常！");
                try {
                    getrespAlarmJudgementBean(reqAlarmJudgementBean);
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.debug("调用告警接口异常！" + e.getMessage());
                }
            }
        }
        TraceUtil.clear();
        return flag;
    }

    /**
     *
     * 查询临时表，转载入库
     *
     * @param
     * @return
     * @author liyakui
     * @since 2019年1月4日 下午5:17:07
     * @version 1.0
     */
    public int bathInsertLoanCompensationStatement(String batchDate) throws Exception {
        int count = 0;
        try {
            LoanCompensationStatementManyiTempVo domainTemp1 = new LoanCompensationStatementManyiTempVo();
            // 查询满易贷临时表
            List<LoanCompensationStatementManyiTempVo> listTemp1 = loanCompensationStatementManyiTempService
                    .queryCompensationStatementManyiTemp(domainTemp1);

            if (listTemp1 != null && listTemp1.size() > 0) {
                @SuppressWarnings("unchecked")
                List<LoanCompensationStatementVo> list = (List<LoanCompensationStatementVo>) beansCopy(listTemp1,
                        LoanCompensationStatementVo.class);
                String date = null;
                for (LoanCompensationStatementVo loanCompensationStatementVo : list) {
                    loanCompensationStatementVo.setCreateTime(batchDate);
                    // 代偿逾期日期格式化"yyyy-MM-dd"
                    date = loanCompensationStatementVo.getSeventyDayOverdueDate();
                    if (StringUtils.isNotBlank(date)) {
                        date = DateUtility.format8To10(date);// date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6);
                        loanCompensationStatementVo.setSeventyDayOverdueDate(date);
                    }
                    loanCompensationStatementVo.setBusinessVariety(BaseConstant.BUSINESS_VARIETY_02);// 满易贷品种
                    // 百度金额单位分转换单位为元
                    // 代偿本金
                    loanCompensationStatementVo.setCompensatoryPrincipal(
                            new BigDecimal(loanCompensationStatementVo.getCompensatoryPrincipal().doubleValue() / 100));
                    // 短期正常本金余额
                    loanCompensationStatementVo
                            .setPrinShortBal(new BigDecimal(loanCompensationStatementVo.getPrinShortBal().doubleValue() / 100));
                    // 中长期正常本金余额
                    loanCompensationStatementVo
                            .setPrinLongBal(new BigDecimal(loanCompensationStatementVo.getPrinLongBal().doubleValue() / 100));
                    // 逾期本金余额
                    loanCompensationStatementVo
                            .setPrinOverBal(new BigDecimal(loanCompensationStatementVo.getPrinOverBal().doubleValue() / 100));
                    // 代偿罚息
                    loanCompensationStatementVo.setCompensatoryPenalty(
                            new BigDecimal(loanCompensationStatementVo.getCompensatoryPenalty().doubleValue() / 100));
                    // 代偿利息
                    loanCompensationStatementVo.setCompensatoryInterest(
                            new BigDecimal(loanCompensationStatementVo.getCompensatoryInterest().doubleValue() / 100));
                }
                // 满易贷批量插入本地库正式表
                count = loanCompensationStatementServiceV2.bathInsert(list);
                logger.info("满易贷批量插入本地库正式表成功！插入条数：" + count);
            }
            // 查询尊享贷临时表
            LoanCompensationStatementEnjoyTempVo domainTemp2 = new LoanCompensationStatementEnjoyTempVo();
            List<LoanCompensationStatementEnjoyTempVo> listTemp2 = loanCompensationStatementEnjoyTempService
                    .queryloanCompensationStatementEnjoyTemp(domainTemp2);
            if (listTemp2 != null && listTemp2.size() > 0) {
                @SuppressWarnings("unchecked")
                List<LoanCompensationStatementVo> list = (List<LoanCompensationStatementVo>) beansCopy(listTemp2,
                        LoanCompensationStatementVo.class);
                String date = null;
                for (LoanCompensationStatementVo loanCompensationStatementVo : list) {
                    loanCompensationStatementVo.setCreateTime(batchDate);
                    // 代偿逾期日期格式化"yyyy-MM-dd"
                    date = loanCompensationStatementVo.getSeventyDayOverdueDate();
                    if (StringUtils.isNotBlank(date)) {
                        date = DateUtility.format8To10(date);// date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6);
                        loanCompensationStatementVo.setSeventyDayOverdueDate(date);
                    }
                    loanCompensationStatementVo.setBusinessVariety(BaseConstant.BUSINESS_VARIETY_01);// 尊享贷品种
                    // 百度金额单位分转换单位为元
                    // 代偿本金
                    loanCompensationStatementVo.setCompensatoryPrincipal(
                            new BigDecimal(loanCompensationStatementVo.getCompensatoryPrincipal().doubleValue() / 100));
                    // 短期正常本金余额
                    loanCompensationStatementVo
                            .setPrinShortBal(new BigDecimal(loanCompensationStatementVo.getPrinShortBal().doubleValue() / 100));
                    // 中长期正常本金余额
                    loanCompensationStatementVo
                            .setPrinLongBal(new BigDecimal(loanCompensationStatementVo.getPrinLongBal().doubleValue() / 100));
                    // 逾期本金余额
                    loanCompensationStatementVo
                            .setPrinOverBal(new BigDecimal(loanCompensationStatementVo.getPrinOverBal().doubleValue() / 100));
                    // 代偿罚息
                    loanCompensationStatementVo.setCompensatoryPenalty(
                            new BigDecimal(loanCompensationStatementVo.getCompensatoryPenalty().doubleValue() / 100));
                    // 代偿利息
                    loanCompensationStatementVo.setCompensatoryInterest(
                            new BigDecimal(loanCompensationStatementVo.getCompensatoryInterest().doubleValue() / 100));
                }
                // 尊享贷批量插入本地库正式表
                count = loanCompensationStatementServiceV2.bathInsert(list);
                logger.info("尊享贷批量插入本地库正式表成功！插入条数：" + count);
            }
        } catch (DuplicateKeyException e1) {
            logger.debug("借据号重复！" + e1.getMessage());
            throw e1;
        } catch (Exception e) {
            logger.debug("插入数据异常!" + e.getMessage());
            throw e;
        }
        return count;
    }

    /**
     *
     * 查询代偿汇总临时表，装载入库正式表
     *
     * @return
     * @author liyakui
     * @since 2019年1月22日 下午5:48:21
     * @version 1.0
     */
    public int insertReconciliationDocuments(String batchDate) throws Exception {
        int count = 0;
        try {
            // 查询尊享汇总临时表数据
            ReconciliationDocumentsEnjoyTempVo reconciliationDocumentsTempVo = new ReconciliationDocumentsEnjoyTempVo();
            List<ReconciliationDocumentsEnjoyTempVo> list = reconciliationDocumentsEnjoyTempService
                    .queryReconciliationDocumentsEnjoyTemp(reconciliationDocumentsTempVo);
            if (list != null && list.size() > 0) {
                @SuppressWarnings("unchecked")
                List<ReconciliationDocumentsVo> reconciliationDocumentsVos = (List<ReconciliationDocumentsVo>) beansCopy(list,
                        ReconciliationDocumentsVo.class);
                for (ReconciliationDocumentsVo reconciliationDocumentsVo : reconciliationDocumentsVos) {
                    reconciliationDocumentsVo.setCreateTime(batchDate);
                    reconciliationDocumentsVo.setBusinessVariety(BaseConstant.BUSINESS_VARIETY_01);// 尊享贷
                    // 百度代偿金额单位分转换为单位元
                    // 代偿本金
                    reconciliationDocumentsVo.setCompensatoryPrincipal(
                            new BigDecimal(reconciliationDocumentsVo.getCompensatoryPrincipal().doubleValue() / 100));
                    // 中长期正常本金余额
                    reconciliationDocumentsVo.setMidLongLoanOutstandPrincipal(
                            new BigDecimal(reconciliationDocumentsVo.getMidLongLoanOutstandPrincipal().doubleValue() / 100));
                    // 短期正常本金余额
                    reconciliationDocumentsVo.setShortLoanOutstandPrincipal(
                            new BigDecimal(reconciliationDocumentsVo.getShortLoanOutstandPrincipal().doubleValue() / 100));
                    // 逾期本金余额
                    reconciliationDocumentsVo.setReturnOfOverdueCurrentPrincipal(
                            new BigDecimal(reconciliationDocumentsVo.getReturnOfOverdueCurrentPrincipal().doubleValue() / 100));
                    // 代偿利息
                    reconciliationDocumentsVo
                            .setReturnOfInterest(new BigDecimal(reconciliationDocumentsVo.getReturnOfInterest().doubleValue() / 100));
                    // 代偿罚息
                    reconciliationDocumentsVo
                            .setReturnOfPenalty(new BigDecimal(reconciliationDocumentsVo.getReturnOfPenalty().doubleValue() / 100));
                }
                // 百度代偿正式表插入数据
                count = reconciliationDocumentsService.batchInsert(reconciliationDocumentsVos);
                logger.info("新增数据成功！成功条数：" + count);
            }

            // 查询满易汇总金额临时表数据
            ReconciliationDocumentsManyiTempVo reconciliationDocumentsManyiTempVo = new ReconciliationDocumentsManyiTempVo();
            List<ReconciliationDocumentsManyiTempVo> reconciliationDocumentsManyiTempVos = reconciliationDocumentsManyiTempService
                    .queryReconciliationDocumentsManyiTemp(reconciliationDocumentsManyiTempVo);
            if (reconciliationDocumentsManyiTempVos != null && reconciliationDocumentsManyiTempVos.size() > 0) {
                @SuppressWarnings("unchecked")
                List<ReconciliationDocumentsVo> reconciliationDocumentsVos = (List<ReconciliationDocumentsVo>) beansCopy(
                        reconciliationDocumentsManyiTempVos, ReconciliationDocumentsVo.class);
                for (ReconciliationDocumentsVo reconciliationDocumentsVo : reconciliationDocumentsVos) {
                    reconciliationDocumentsVo.setCreateTime(batchDate);
                    reconciliationDocumentsVo.setBusinessVariety(BaseConstant.BUSINESS_VARIETY_02);// 满易贷
                    // 百度代偿金额单位分转换为单位元
                    // 代偿本金
                    reconciliationDocumentsVo.setCompensatoryPrincipal(
                            new BigDecimal(reconciliationDocumentsVo.getCompensatoryPrincipal().doubleValue() / 100));
                    // 中长期正常本金余额
                    reconciliationDocumentsVo.setMidLongLoanOutstandPrincipal(
                            new BigDecimal(reconciliationDocumentsVo.getMidLongLoanOutstandPrincipal().doubleValue() / 100));
                    // 短期正常本金余额
                    reconciliationDocumentsVo.setShortLoanOutstandPrincipal(
                            new BigDecimal(reconciliationDocumentsVo.getShortLoanOutstandPrincipal().doubleValue() / 100));
                    // 逾期本金余额
                    reconciliationDocumentsVo.setReturnOfOverdueCurrentPrincipal(
                            new BigDecimal(reconciliationDocumentsVo.getReturnOfOverdueCurrentPrincipal().doubleValue() / 100));
                    // 代偿利息
                    reconciliationDocumentsVo
                            .setReturnOfInterest(new BigDecimal(reconciliationDocumentsVo.getReturnOfInterest().doubleValue() / 100));
                    // 代偿罚息
                    reconciliationDocumentsVo
                            .setReturnOfPenalty(new BigDecimal(reconciliationDocumentsVo.getReturnOfPenalty().doubleValue() / 100));
                }

                // 百度代偿正式表插入数据
                count = reconciliationDocumentsService.batchInsert(reconciliationDocumentsVos);
                logger.info("新增数据成功！成功条数：" + count);
            }
        } catch (Exception e) {
            count = -1;
            logger.debug("新增数据异常" + e.getMessage());
            throw e;
        }
        return count;
    }

    /**
     *
     * 多借多贷接口
     *
     * @param respBorrowingMoreBean
     * @return
     * @author liyakui
     * @since 2019年1月22日 下午2:50:30
     * @version 1.0
     */
    public RespBorrowingMoreBean getRespBorrowingMoreBean(RespBorrowingMoreBean respBorrowingMoreBean,String batchDate) throws Exception {
        try {
            // 获取汇总金额list
            List<BigDecimal> amounts = getAmounts(batchDate);
            // 从冻结流水配置表查询通知书号
            FreezFlowBasiVo freezFlowBasiVo = new FreezFlowBasiVo();
            freezFlowBasiVo = freezFlowBasiService.selectFreezFlowBasi(freezFlowBasiVo);
            if (freezFlowBasiVo == null) {
                throw new ESBException("冻结流水配置表查询数据为空！");
            }
            // 调用多借多贷接口
            ReqBorrowingMoreBean reqBorrowingMoreBean = new ReqBorrowingMoreBean();
            reqBorrowingMoreBean.setTxnVrty("MS2005");// 交易类别
            reqBorrowingMoreBean.setCurrCd("156");// 交易币种
            reqBorrowingMoreBean.setSmyCd("BR");// 摘要码
            reqBorrowingMoreBean.setBizVchrTp("");// 业务凭证类型,默认为空
            reqBorrowingMoreBean.setBizVchrNo("");// 业务凭证号码,默认为空
            reqBorrowingMoreBean.setMainTransAmt(amounts.get(6));// 主交易金额,发起代偿的金额汇总
            reqBorrowingMoreBean.setTranRmk("");// 转账附言
            reqBorrowingMoreBean.setRcrCd("");// 支付令编号
            reqBorrowingMoreBean.setBdgtSbjCd("");// 预算科编码，网贷不需要
            reqBorrowingMoreBean.setBdgtTrgtCd("");// 预算指标编码，网贷不需要
            reqBorrowingMoreBean.setEcnmSbjCd("");// 经济科编码，网贷不需要
            reqBorrowingMoreBean.setVerfAcctNmFlg("1");// 是否检验户名，默认检验为0
            reqBorrowingMoreBean.setChkTlrNo("");// 复核柜员，默认为空
            // caoxin：2019年4月8日 修改都接多贷接口前置日期为当前日期
            reqBorrowingMoreBean.setPrevDt(DateUtility.format10To8(DateUtility.getCurrAppDateStr()));// 必输，前置日期
            reqBorrowingMoreBean.setPrevFlowNo(generatorPreSerialNumber());// 必输，前置流水号
            reqBorrowingMoreBean.setPrevSysNo(INTERNET_LOAN_SYSTEM_ID);// 必输，前置系统编号(OCM)
            reqBorrowingMoreBean.setBizCd(BAIDUCOMPENSATION);// 业务代码
            reqBorrowingMoreBean.setUsrID(usrId);// 用户ID
            // 记账明细信息list
            List<BkkpDtlInf> bkkpDtlInfArry = new ArrayList<BkkpDtlInf>();
            // 查询配置表账户信息
            LoanAccNoVo loanAccNo = new LoanAccNoVo();
            List<LoanAccNoVo> listLoanAccNos = loanAccNoService.queryLoanAccNo(loanAccNo);
            if (listLoanAccNos == null) {
                throw new ESBException("账户配置表没有账户信息！");
            }

            int count = 0;
            for (LoanAccNoVo loanAccNo2 : listLoanAccNos) {
                count += new Integer(loanAccNo2.getAccountSize());

                BkkpDtlInf bkkpDtlInf = new BkkpDtlInf();
                bkkpDtlInf.setAcctNo(loanAccNo2.getAccountNo());// 账号
                bkkpDtlInf.setAcctNm(loanAccNo2.getAccountName());// 账号名称
                bkkpDtlInf.setSmyCd("BR");// 摘要码,自行填写有意义的摘要码
                if ("A".equals(loanAccNo2.getAcconutType())) {
                    // 西安春禾保证金户
                    reqBorrowingMoreBean.setMainAcctNo(loanAccNo2.getAccountNo());// 主账号,填：保证金互账号
                    for (int i = 0; i < new Integer(loanAccNo2.getAccountSize()); i++) {
                        BkkpDtlInf bkkpDtlInf2 = new BkkpDtlInf();
                        bkkpDtlInf2.setAcctNo(loanAccNo2.getAccountNo());// 账号
                        bkkpDtlInf2.setAcctNm(loanAccNo2.getAccountName());// 账号名称
                        bkkpDtlInf2.setSmyCd("BR");// 摘要码,自行填写有意义的摘要码
                        bkkpDtlInf2.setTransAmt(amounts.get(i));// 交易金额
                        bkkpDtlInf2.setDbLndFlg(loanAccNo2.getDcDlag());// 借贷标记（借）
                        bkkpDtlInf2.setAcctSetNo(i + 1 + "");// 财务套号
                        bkkpDtlInfArry.add(bkkpDtlInf2);
                    }

                } else if ("B".equals(loanAccNo2.getAcconutType())) {
                    // 12DL个人百度中长期联合贷款
                    bkkpDtlInf.setTransAmt(amounts.get(0));// 中长期正常本金余额
                    bkkpDtlInf.setDbLndFlg(loanAccNo2.getDcDlag());// 借贷标记（贷）
                    bkkpDtlInf.setAcctSetNo("1");// 财务套号
                    bkkpDtlInfArry.add(bkkpDtlInf);
                }

                else if ("C".equals(loanAccNo2.getAcconutType())) {
                    // 12DK个人百度短期联合贷款
                    bkkpDtlInf.setTransAmt(amounts.get(1));// 短期正常本金余额
                    bkkpDtlInf.setDbLndFlg(loanAccNo2.getDcDlag());// 借贷标记（贷）
                    bkkpDtlInf.setAcctSetNo("2");// 财务套号
                    bkkpDtlInfArry.add(bkkpDtlInf);
                } else if ("D".equals(loanAccNo2.getAcconutType())) {
                    // 12DM个人逾期百度联合贷款
                    bkkpDtlInf.setTransAmt(amounts.get(2));// 逾期本金余额
                    bkkpDtlInf.setDbLndFlg(loanAccNo2.getDcDlag());// 借贷标记（贷）
                    bkkpDtlInf.setAcctSetNo("3");// 财务套号
                    bkkpDtlInfArry.add(bkkpDtlInf);
                } else if ("E".equals(loanAccNo2.getAcconutType())) {
                    // 13AJ个人百度联合贷款应收利息
                    bkkpDtlInf.setTransAmt(amounts.get(3));// 代偿利息
                    bkkpDtlInf.setDbLndFlg(loanAccNo2.getDcDlag());// 借贷标记（付）
                    bkkpDtlInf.setAcctSetNo("4");// 财务套号
                    bkkpDtlInfArry.add(bkkpDtlInf);
                } else if ("F".equals(loanAccNo2.getAcconutType())) {
                    // 50CH个人百度联合贷款利息收入
                    bkkpDtlInf.setTransAmt(amounts.get(4));// 代偿罚息
                    bkkpDtlInf.setDbLndFlg(loanAccNo2.getDcDlag());// 借贷标记（付）
                    bkkpDtlInf.setAcctSetNo("5");// 财务套号
                    bkkpDtlInfArry.add(bkkpDtlInf);
                } else if ("G".equals(loanAccNo2.getAcconutType())) {
                    // 714个人百度联合贷款应收未收利息
                    bkkpDtlInf.setTransAmt(amounts.get(4));// 代偿罚息
                    bkkpDtlInf.setDbLndFlg(loanAccNo2.getDcDlag());// 借贷标记（付）
                    bkkpDtlInf.setAcctSetNo("6");// 财务套号
                    bkkpDtlInfArry.add(bkkpDtlInf);
                }

            }
            reqBorrowingMoreBean.setEntrCnt(count + "");// 分录笔数,单边笔数，一借一贷，算两笔

            reqBorrowingMoreBean.setBkkpDtlInfArry(bkkpDtlInfArry);
            respBorrowingMoreBean = borrowingMoreService.borrowingMore(reqBorrowingMoreBean);

        } catch (Exception e) {
            logger.debug("调用多借多贷接口异常！" + e.getMessage());
            throw e;
        }

        return respBorrowingMoreBean;
    }


    /**
     * 调用颖风写的告警判断服务
     *
     * @param reqAlarmJudgementBean
     * @return
     * @throws Exception
     * @author liyakui
     * @version 1.0
     * @since 2019年1月28日 上午8:36:25
     */
    public RespAlarmJudgementBean getrespAlarmJudgementBean(ReqAlarmJudgementBean reqAlarmJudgementBean) throws Exception {
        RespAlarmJudgementBean respAlarmJudgementBean = null;
        try {
            // 调用颖风写的告警判断服务
            reqAlarmJudgementBean.setMonObjNm("网贷批量");
            reqAlarmJudgementBean.setMonObjSpfTpVal("百度");
            reqAlarmJudgementBean.setMonObjLctr(InetAddress.getLocalHost().getHostAddress());// 获取本机IP
            reqAlarmJudgementBean.setAlrmTmstmp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date())));
            reqAlarmJudgementBean.setMonAlrmLvl("3");
            respAlarmJudgementBean = alarmJudgementService.alarmJudgement(reqAlarmJudgementBean);
            logger.debug("调用告警判断返回码：【" + respAlarmJudgementBean.getRetCd() + "】，返回信息：【" + respAlarmJudgementBean.getRetMsg() + "】");
        } catch (Exception e) {
            logger.info("调用告警接口异常！" + e.getMessage());
            throw e;
        }
        return respAlarmJudgementBean;
    }

    /**
     *
     * 根据日期查询汇总金额
     *
     * @return
     * @author liyakui
     * @since 2019年1月24日 下午2:20:40
     * @version 1.0
     */
    public List<BigDecimal> getAmounts(String batchDate) throws Exception {
        List<BigDecimal> amounts = new ArrayList<BigDecimal>();
        try {
            // 根据日期查询代偿汇总数据
            ReconciliationDocumentsVo reconciliationDocumentsVo = new ReconciliationDocumentsVo();
            reconciliationDocumentsVo.setCreateTime(batchDate);// 设置当前日期
            Map<String, BigDecimal> map = reconciliationDocumentsService.queryRecDocSumBal(reconciliationDocumentsVo);
            if (map != null && map.size() > 0) {
                // 获取相关汇总金额
                BigDecimal compensatoryPrincipal = map.get("compensatory_principal");// 代偿本金
                BigDecimal midBigDecimalLoanOutstandPrincipal = map.get("mid_long_loan_outstand_principal");// 中长期贷款剩余未还本金
                BigDecimal shortLoanOutstandPrincipal = map.get("short_loan_outstand_principal");// 短期贷款剩余未还本金
                BigDecimal returnOfOverdueCurrentPrincipal = map.get("return_of_overdue_current_principal");// 归还逾期当前本金
                BigDecimal returnOfInterest = map.get("return_of_interest");// 归还利息
                BigDecimal returnOfPenalty = map.get("return_of_penalty");// 归还罚息
                BigDecimal mainTransAmt = midBigDecimalLoanOutstandPrincipal.add(shortLoanOutstandPrincipal)
                        .add(returnOfOverdueCurrentPrincipal).add(returnOfInterest).add(returnOfPenalty);// 主交易金额(除代偿本金外汇总)

                // 把汇总文件汇总金额放进list，方便调用多借多贷取数
                amounts.add(midBigDecimalLoanOutstandPrincipal);
                amounts.add(shortLoanOutstandPrincipal);
                amounts.add(returnOfOverdueCurrentPrincipal);
                amounts.add(returnOfInterest);
                amounts.add(returnOfPenalty);
                amounts.add(compensatoryPrincipal);
                amounts.add(mainTransAmt);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.debug("查询金额汇总异常！" + e.getMessage());
            throw e;
        }
        return amounts;
    }

    /**
     *
     * 校验各类汇总金额是否匹配一致
     *
     * @author liyakui
     * @since 2019年1月24日 上午11:26:43
     * @version 1.0
     */
    public void checkPrinBal(String batchDate) throws Exception {
        logger.info("校验各类汇总金额是否匹配开始！");
        try {
            // 根据日期获取代偿汇总数据
            ReconciliationDocumentsVo reconciliationDocumentsVo = new ReconciliationDocumentsVo();
            reconciliationDocumentsVo.setCreateTime(batchDate);// 设置当前日期
            Map<String, BigDecimal> map = reconciliationDocumentsService.queryRecDocSumBal(reconciliationDocumentsVo);
            // 根据当前日期查询代偿清单
            LoanCompensationStatementVo loanCompensationStatementVo = new LoanCompensationStatementVo();
            loanCompensationStatementVo.setCreateTime(batchDate);
            List<LoanCompensationStatementVo> loanCompensationStatementVos = loanCompensationStatementServiceV2
                    .queryLoanCompensationStatementByDate(loanCompensationStatementVo);
            // 根据日期查询代偿清单汇总金额
            Map<String, BigDecimal> list = loanCompensationStatementServiceV2.querySumBal(loanCompensationStatementVo);
            if (list != null && list.size() > 0 && map != null && map.size() > 0) {
                // 校验各类清单汇总金额和汇总文件金额是否一致
                int count = 0;
                // 中长期正常本金余额
                if (map.get("mid_long_loan_outstand_principal").equals(list.get("prin_long_bal"))) {
                    count++;
                }
                // 短期正常本金余额
                if (map.get("short_loan_outstand_principal").equals(list.get("prin_short_bal"))) {
                    count++;
                }
                // 逾期本金余额
                if (map.get("return_of_overdue_current_principal").equals(list.get("prin_over_bal"))) {
                    count++;
                }
                // 代偿利息
                if (map.get("return_of_interest").equals(list.get("compensatory_interest"))) {
                    count++;
                }
                // 代偿罚息
                if (map.get("return_of_penalty").equals(list.get("compensatory_penalty"))) {
                    count++;
                }
                // 代偿本金
                if (map.get("compensatory_principal").equals(list.get("compensatory_principal"))) {
                    count++;
                }

                ReconciliationDocumentsVo reconciliationDocumentsVo2 = new ReconciliationDocumentsVo();
                reconciliationDocumentsVo2.setCreateTime(batchDate);// 设置当前日期
                if (count == 6) {
                    // 如果各类金额汇总一致，则通过，更新汇总文件表状态为通过
                    reconciliationDocumentsVo2.setCheckSts(BaseConstant.CHECK_STS_01);// 通过
                    reconciliationDocumentsService.updateReconciliationDocuments(reconciliationDocumentsVo2);
                    for (LoanCompensationStatementVo loanCompensationStatementVo2 : loanCompensationStatementVos) {
                        loanCompensationStatementVo2.setCheckSts(BaseConstant.CHECK_STS_01);
                        // 更新代偿清单文件并账状态
                        loanCompensationStatementServiceV2.updateByBillNo(loanCompensationStatementVo2);
                    }
                } else {
                    // 反之不通过
                    // 更新汇总文件并账状态
                    reconciliationDocumentsVo2.setCheckSts(BaseConstant.CHECK_STS_02);// 未通过
                    reconciliationDocumentsService.updateReconciliationDocuments(reconciliationDocumentsVo2);

                    for (LoanCompensationStatementVo loanCompensationStatementVo2 : loanCompensationStatementVos) {
                        loanCompensationStatementVo2.setCheckSts(BaseConstant.CHECK_STS_02);
                        // 更新代偿清单文件并账状态
                        loanCompensationStatementServiceV2.updateByBillNo(loanCompensationStatementVo2);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.debug("金额校验异常！" + e.getMessage());
            throw e;
        }
    }

    /**
     *
     * 设置解冻请求bean
     *
     * @param reqUnfreezingAccountFundsBean
     * @return
     * @author liyakui
     * @since 2019年1月14日 下午3:39:09
     * @version 1.0
     */
    public List<Object> getReqUnfreezingAccountFundsBean(ReqUnfreezingAccountFundsBean reqUnfreezingAccountFundsBean) throws Exception {
        boolean flag = true;
        List<Object> list = new ArrayList<>();
        try {
            // 查询解冻冻结流水配置表
            FreezFlowBasiVo freezFlowBasiVo = new FreezFlowBasiVo();
            freezFlowBasiVo = freezFlowBasiService.selectFreezFlowBasi(freezFlowBasiVo);
            if (freezFlowBasiVo == null) {
                throw new ESBException("冻结解冻流水配置表没有数据！");
            }
            // 查询保证金账户
            LoanAccNoVo loanAccNoVo = new LoanAccNoVo();
            List<LoanAccNoVo> loanAccNoVos = loanAccNoService.queryLoanAccNo(loanAccNoVo);
            String accLoanNo = null;
            for (LoanAccNoVo loanAccNoVo2 : loanAccNoVos) {
                if ("A".equals(loanAccNoVo2.getAcconutType())) {
                    accLoanNo = loanAccNoVo2.getAccountNo();
                }
            }
            // 判断是否第一次投产查询配置表
            if ("Y".equals(freezFlowBasiVo.getOriSts())) {
                // Y为第一次投产状态
                reqUnfreezingAccountFundsBean.setOriFrzDt(freezFlowBasiVo.getOriFrzDt());// 原冻结日期
                reqUnfreezingAccountFundsBean.setOriFrzFlowNo(freezFlowBasiVo.getOriFrzFlowNo());// 原冻结流水
            } else {
                // 解冻前调用冻结查证接口
                RespVerificationFreezingAndThgBean respVerificationFreezingAndThgBean = new RespVerificationFreezingAndThgBean();
                respVerificationFreezingAndThgBean = getVerificationFreezingAndThg(respVerificationFreezingAndThgBean, "1", 0);// "0"解冻，"1"为冻结
                if (!"0000".equals(respVerificationFreezingAndThgBean.getWrongCd())) {
                    flag = false;
                    // 查证接口返回不成功，则抛异常调用告警接口，不再调用解冻接口
                    ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                    reqAlarmJudgementBean.setAlrmInf("调用查证接口失败！");
                    getrespAlarmJudgementBean(reqAlarmJudgementBean);
                }
                reqUnfreezingAccountFundsBean.setOriFrzDt(respVerificationFreezingAndThgBean.getFrzDt());// 原冻结日期
                reqUnfreezingAccountFundsBean.setOriFrzFlowNo(respVerificationFreezingAndThgBean.getFrzFlowNo());// 原冻结流水
            }
            reqUnfreezingAccountFundsBean.setTxnVrty("MS2025");// 交易类型,可不输
            reqUnfreezingAccountFundsBean.setAdvBookNo("");// 通知书类别,非必输
            reqUnfreezingAccountFundsBean.setAdvBookNo("");// 通知书号，非必输
            reqUnfreezingAccountFundsBean.setAcctNo(accLoanNo);// 西安春禾的保证金账号
            reqUnfreezingAccountFundsBean.setUnFrzTp("03");// 与冻结类型一致
            reqUnfreezingAccountFundsBean.setUnFrzAmt("");// 解冻金额，不送
            reqUnfreezingAccountFundsBean.setSmyRmk("");// 摘要，非必输
            reqUnfreezingAccountFundsBean.setAuthUsrNo("");// 授权用户，非必输
            reqUnfreezingAccountFundsBean.setPrevDt(DateUtility.format10To8(DateUtility.getCurrAppDateStr()));// 前置日期，非必输
            reqUnfreezingAccountFundsBean.setPrevFlowNo("");// 前置流水号，非必输
            reqUnfreezingAccountFundsBean.setPrevSysNo(INTERNET_LOAN_SYSTEM_ID);// 前置系统编号
            reqUnfreezingAccountFundsBean.setBizCd(BAIDUCOMPENSATION);// 业务代码，非必输
            reqUnfreezingAccountFundsBean.setUsrID(usrId);// 用户ID
            list.add(reqUnfreezingAccountFundsBean);
            list.add(flag);
        } catch (Exception e) {
            logger.debug("设置解冻bean异常！" + e.getMessage());
            throw e;
        }

        return list;
    }

    /**
     * 解冻或冻结查证请求
     *
     * @param respVerificationFreezingAndThgBean
     * @return
     * @throws Exception
     * @author liyakui
     * @version 1.0
     * @since 2019年1月8日 上午9:35:04
     */
    public RespVerificationFreezingAndThgBean getVerificationFreezingAndThg(
            RespVerificationFreezingAndThgBean respVerificationFreezingAndThgBean, String type, int count) throws Exception {
        boolean result = false;
        ReqVerificationFreezingAndThgBean reqVerificationFreezingAndThgBean = new ReqVerificationFreezingAndThgBean();
        try {
            // 从冻结流水配置表查询通知书号
            FreezFlowBasiVo freezFlowBasiVo = new FreezFlowBasiVo();
            freezFlowBasiVo = freezFlowBasiService.selectFreezFlowBasi(freezFlowBasiVo);
            // 查询保证金账户

            if (freezFlowBasiVo == null) {
                throw new ESBException("冻结解冻查证配置表没有数据！");
            }

            // 查询保证金账户
            LoanAccNoVo loanAccNoVo = new LoanAccNoVo();
            List<LoanAccNoVo> loanAccNoVos = loanAccNoService.queryLoanAccNo(loanAccNoVo);
            String accLoanNo = null;
            for (LoanAccNoVo loanAccNoVo2 : loanAccNoVos) {
                if ("A".equals(loanAccNoVo2.getAcconutType())) {
                    accLoanNo = loanAccNoVo2.getAccountNo();
                }
            }
            reqVerificationFreezingAndThgBean.setTxnVrty("MS2029");// 交易类型
            if ("0".equals(type)) {
                // 0为解冻
                reqVerificationFreezingAndThgBean.setVerfTp("0");// 0为解冻1为冻结
            } else {
                // 1为冻结
                reqVerificationFreezingAndThgBean.setVerfTp("1");// 0为解冻1为冻结
            }
            reqVerificationFreezingAndThgBean.setOriFrzDt("");// 原冻结日期，查询类型为0解冻时有效
			reqVerificationFreezingAndThgBean.setOriFrzFlowNo("20190109");// 原冻结流水号，查询类型为0解冻时有效
            reqVerificationFreezingAndThgBean.setAdvBookTp("O");// 通知书类型，N协助冻结解冻通知书，M质押冻结解冻通知书，O其他，默认是其他
            reqVerificationFreezingAndThgBean.setAdvBookNo(freezFlowBasiVo.getAdvBookNo());// 通知书号(需要上送流水号)
            reqVerificationFreezingAndThgBean.setAcctNo(accLoanNo);// 账号
            reqVerificationFreezingAndThgBean.setFrzTp("03");// 冻结类型，1部分冻结，2不进不出，3只进不出，查询类型为1冻结时有效
            reqVerificationFreezingAndThgBean.setFrzAmt("");// 冻结金额，冻结类型为"1部分冻结"时有效，查询类型为1冻结时有效
            reqVerificationFreezingAndThgBean.setUsrID(usrId);// 用户ID
            respVerificationFreezingAndThgBean = verificationFreezingAndThgService
                    .verificationFreezingAndThg(reqVerificationFreezingAndThgBean);

        } catch (Exception e) {
            result = true;
            logger.debug("解冻或者冻结查证接口异常！" + e.getMessage());

        }
        if (result) {
            count++;
            if (count < 3) {
                // 解冻或者冻结查证异常或超时
                getVerificationFreezingAndThg(respVerificationFreezingAndThgBean, type, count);
            } else {
                // 调用3次查证后异常或超时处理
                logger.debug("调用查证异常！返回结果：" + respVerificationFreezingAndThgBean.toString());
                // 告警
                // 调用颖风写的告警判断服务
                ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
                reqAlarmJudgementBean.setAlrmInf("百度代偿调用解冻或冻结查证接口异常！");
                getrespAlarmJudgementBean(reqAlarmJudgementBean);
                // 抛出查证异常
                throw new ESBException("调用解冻或者冻结查证接口异常！");

            }

        }
        return respVerificationFreezingAndThgBean;
    }

    /**
     * 交互文件服务-并账文件解析
     *
     * @return boolean
     * @throws Exception
     * @author liyakui
     * @version 1.0
     * @since 2019年1月9日 上午9:09:16
     */
    @Override
    public boolean analysisFile() throws Exception {
        // boolean fileDownRes = downloadFile();// 前置文件服务器下载文件
        boolean result = false;
        // 1、解压同步文件
        File files = new File(baiduMyFilePath);// 解析文件
        if (files.exists()) {
            File[] accFiles = files.listFiles();
            if (accFiles.length > 0) {
                for (File accFile : accFiles) {
                    if (accFile.getName().endsWith(ZipUtil.EXT)) {// 同步文件

                        try {
                            // 1、解压同步文件
                            result = ZipUtil.unZipSig(new File(accFile.getAbsolutePath()),
                                    new File(accFile.getAbsolutePath().replace(ZipUtil.EXT, "")));
                        } catch (IOException e) {
                            logger.error("交互文件服务-并账文件解压出现异常，异常信息" + e.getMessage());
                            e.printStackTrace();
                            throw new IOException();
                        }

                    }
                }
            }

        }
        return result;
    }

    /**
     * 从前置文件服务器下载文件
     *
     * @return
     * @throws Exception
     * @author liyakui
     * @version 1.0
     * @since 2019年1月15日 上午8:54:23
     */
    @SuppressWarnings("unused")
    private boolean downloadFile(String remotePath, String remoteFileName, String localFilePath, String localFileName, boolean closeFlag)
            throws Exception {
        // 连接前置文件服务器
        SFTPUtil sftpUtil = null;
        boolean fileDownRes = false;// 下载文件是否成功
        int downTotal = 0;
        try {
            // 从前置文件服务器下载文件到本地
            sftpUtil = new SFTPUtil(hjUserName, hjPassword, hjFtpHost, hjFtpPort);

            // 检测解析目录是否有需要解析的文件存在
            Vector<ChannelSftp.LsEntry> files = sftpUtil.ls(remotePath);
            Objects.requireNonNull(files);// 文件不允许为空

            for (ChannelSftp.LsEntry file : files) {
                String fileName = file.getFilename();// 下载文件名
                if (".".equals(fileName) || "..".equals(fileName)) {
                    continue;
                } else {
                    try {
                        boolean singleFileDownRes = sftpUtil.downFile(sftpUtil, remotePath, file.getFilename(), baiduZxFilePath,
                                file.getFilename(), false);
                        logger.info("前置文件服务器下载文件：" + remotePath + file.getFilename() + "，结果[" + singleFileDownRes + "]");
                        if (singleFileDownRes) {
                            downTotal++;// 下载文件数
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger.error("前置文件服务器下载文件出现异常：" + e.getMessage());
                    }
                }
            }
            if (downTotal > 0) {// 下载文件数大于0，则解析
                fileDownRes = true;
            }
            logger.info("本次前置文件服务器下载文件数目：[" + downTotal + "]");
        } catch (FileSystemException e) {
            logger.error("前置文件服务器下载文件出现异常：" + e.getMessage());
            e.printStackTrace();
        } catch (JSchException e) {
            logger.error("前置文件服务器下载文件出现异常：" + e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            logger.error("前置文件服务器下载文件出现异常：" + e.getMessage());
            e.printStackTrace();
        } finally {
            if (sftpUtil != null) {
                sftpUtil.closeSFTP();
            }
        }
        return fileDownRes;
    }
    /**
     * 逾期代偿推送原 百度代偿解冻，冻结，多借多贷数据推送到互联网金融平台: <br>
     * <p>
     * 0.1:caoxin:2019/4/2 15:56: TODO【前置流水号生成规则，业务代码BDDC，前置系统编号OCM，前置日期需要从0402分支合并】
     *     caoxin:告警信息还没有写 <br>
     *
     * @return
     * @author caoxin
     * @date 2019/4/2 15:56
     * @version 0.1
     * @since 2019/4/2 15:56
     */
    @Override
    public boolean pushLoadCompensationDataToIntenetFinancePlatform(String batchDate)throws Exception {
        boolean flag = false;
        // 创建请求实体基础信息
        ReqCompensationBean reqCompensationBean = new ReqCompensationBean();
        try {
            // 设置请求实体基本信息
            setReqCompensationBeanInfo(reqCompensationBean,batchDate);
        } catch (Exception e) {
            String msg1 = "+++++=====>生成前置流水号失败，前置流水号在数据库没有初始化!<=====+++++";
            logger.error(msg1,msgTemplate);
            String msg2 = "+++++=====>异常信息<=====+++++";
            logger.error(msg2,msgTemplate);
            logger.error(e.getMessage(),msgTemplate);
            return  flag;
        }
        // 查询汇总金额
        List<BigDecimal> amountSummary = getAmounts(batchDate);
        // 查询配置表账户信息
        LoanAccNoVo loanAccNo = new LoanAccNoVo();
        List<LoanAccNoVo> loanAccNos = loanAccNoService.queryLoanAccNo(loanAccNo);
        if (loanAccNos!= null && !loanAccNos.isEmpty()) {
            if (amountSummary != null && !amountSummary.isEmpty()) {
                // 设置分录笔数
                reqCompensationBean.setEntrCnt(getEntrCnt(loanAccNos));
                // 设置主账号,填：保证金互账号
                reqCompensationBean.setMainAcctNo(getXiAnMarginAccount(loanAccNos));
                // 设置主交易金额,发起代偿的金额汇总
                reqCompensationBean.setMainTransAmt(amountSummary.get(MAINTRANSAMT_INDEX));
                // 获取记账明细
                List<BkkpDtlInf> bkkpDtlInfList = getBkkpDtlInfList(loanAccNos, amountSummary);
                // 记账明细List
                reqCompensationBean.setBkkpDtlInfArry(bkkpDtlInfList);
                setOnlineFinance(reqCompensationBean);
                flag = true;
            } else {
                String msg = "+++++=====>查询汇总金额没有信息,封装推送的传统核心的Bean失败<=====+++++";
                logger.error(msg,msgTemplate);
                return flag;
            }
        } else {
            String msg = "++++====>账户配置表没有账户信息！<=====+++++";
            logger.error(msg,msgTemplate);
            return flag;
        }
        // 发送百度逾期代偿数据消息接口
        if (flag){
            boolean result = pushCompensationDataService.pushCompensationDataToInternetFinancePlatform(reqCompensationBean);
            // 告警
            callAlarm(result);
        }
        return flag;
    }

    /**
     * 判断互联网金融平台是否完成多借多贷任务处理: <br>
     *
     * 0.1:caoxin:2019/4/4 11:46: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/4 11:46
     * @date 2019/4/4 11:46
     * @version 0.1
     */
    @Override
    public boolean isHandleCompensationOk(String batchDate) throws Exception {
        String msg = batchDate +":=====>>>>>轮询判断代偿是否成功处理开始<<<<<=====";
        logger.info(msg,msgTemplate);
        // 当日并账明细数量
        int countCompensationNum = needToCountNum(batchDate);
        String msg1 = "=====>>>>>当日并账明细数量<<<<<===== " + countCompensationNum;
        logger.info(msg1,msgTemplate);
        if (countCompensationNum == 0){
            logger.info("当日并账明细数量为 0， 不用更新对账明细!");
            return true;
        }
        // 统计当天代偿明细状态为成功的数量
        String msg2 = "=====>>>>>当日已完成并账明细数量<<<<<===== " + countCompensationNum;
        int finishedCompensationNum = getFinishedCompensationNum(batchDate);
        logger.info(msg2,msgTemplate);
        // 相差数量
        int differNum = countCompensationNum - finishedCompensationNum;
        // 等待时间
        long waitTimeMinutes = 1;
        // 代偿结果
        boolean result = true;
        while(differNum != finishedCompensationNum && countCompensationNum != 0) {
            // 通过代偿成功状态和并账状态
            try {

                TimeUnit.MINUTES.sleep(waitTimeMinutes);
                String msg3 = DateUtility.getCurrAppDateStr() +":=====>>>>>轮询判断代偿未成功：等待"+waitTimeMinutes+"mins <<<<<=====";
                logger.info(msg3,msgTemplate);
                finishedCompensationNum = getFinishedCompensationNum(batchDate);
                waitTimeMinutes++;
                // 判断如果开始更新代偿明细时就再等待一秒
                if ((differNum - finishedCompensationNum) < differNum && (differNum - finishedCompensationNum) != 0) {
                    TimeUnit.SECONDS.sleep(1);
                    waitTimeMinutes = 0;
                }
                if(waitTimeMinutes == 9){
                    throw new InterruptedException("等待互联网金融平台返回数据超过48分钟");
                }

            } catch (InterruptedException e) {
                String errormsg = "=====>轮询代偿明细等待被打断,成功代偿更新数量："+finishedCompensationNum+",需要更新代偿数量"+countCompensationNum+"<=====";
                if (finishedCompensationNum != countCompensationNum){
                    result = false;
                }
                logger.info(errormsg, msgTemplate);
                throw new Exception("=====>轮询代偿明细等待被打断等待结束，轮询任务执行失败<=====");
            }
        }
        logger.info("=====>轮询代偿明细成功，代偿成功<=====",msgTemplate);
        return result;
    }

    /**
     * 发送逾期代偿如果失败则发送告警信息: <br>
     *
     * 0.1:caoxin:2019/4/12 11:13: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/12 11:13
     * @date 2019/4/12 11:13
     * @version 0.1
     */

    private void callAlarm(boolean result) throws ESBException {
        if (!result){
            ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
            reqAlarmJudgementBean.setAlrmInf("++++====>百度代偿推送数据到互金平台失败！<=====+++++");
            try {
                getrespAlarmJudgementBean(reqAlarmJudgementBean);
            } catch (Exception e) {
                throw new ESBException("++++====>调用告警信息出现异常<=====+++++");
            }
            throw new ESBException("++++====>百度代偿推送数据到互金平台失败<=====+++++");
        }
    }

    /**
     * 设置互联网金融公共信息: <br>
     *
     * 0.1:caoxin:2019/4/12 11:11: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/12 11:11
     * @date 2019/4/12 11:11
     * @version 0.1
     */
    private void setOnlineFinance(ReqCompensationBean reqCompensationBean) {
        // 设置互联网金融公共信息
        reqCompensationBean.setSvcFld(HjConstant.SERVICE_DOMAIN_MBSD_BP_LM);
        reqCompensationBean.setSvcTp(HjConstant.SERVICE_TYPE_1000);
        reqCompensationBean.setServiceCd(HjConstant.SERVICE_CODE_0203);
    }

    /**
     * 统计已成功代偿的数量: <br>
     *
     * 0.1:caoxin:2019/4/14 10:36: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/14 10:36
     * @date 2019/4/14 10:36
     * @version 0.1
     */
    private int getFinishedCompensationNum(String batchDate) {
        LoanCompensationStatementVo loanCompensationStatementVo = new LoanCompensationStatementVo();
        // 设置并账状态为01
        loanCompensationStatementVo.setCheckSts(BaseConstant.CHECK_STS_01);
        // 设置对账状态为03
        loanCompensationStatementVo.setCompensationSts(BaseConstant.COMPENSATION_STS_03);
        // 设置业务日期
        loanCompensationStatementVo.setCreateTime(batchDate);
        return loanCompensationStatementServiceV2.countLoanCompensationStatementByCheckState(loanCompensationStatementVo);
    }

    /**
     * 统计并账明细总数: <br>
     *
     * 0.1:caoxin:2019/4/14 10:32: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/14 10:32
     * @date 2019/4/14 10:32
     * @version 0.1
     */

    private int needToCountNum(String batchDate) {
        // 查询当前数库的字段
        LoanCompensationStatementVo loanCompensationStatementVo = new LoanCompensationStatementVo();
        loanCompensationStatementVo.setCreateTime(batchDate);
        List<LoanCompensationStatementVo> loanCompensationStatementVos;
        int needCompensationCount = 0;
        try {
            loanCompensationStatementVos= loanCompensationStatementServiceV2.queryLoanCompensationStatementByDate(loanCompensationStatementVo);
            if (loanCompensationStatementVos !=  null && !loanCompensationStatementVos.isEmpty()){
                needCompensationCount = loanCompensationStatementVos.size();
            }
        } catch (Exception e) {
            logger.error("通过日期查询对账明细出现错误!");
        }
        return needCompensationCount;
    }

    /**
     * 获取记账明细List: <br>
     * <p>
     * 0.1:caoxin:2019/4/3 9:10: TODO: <br>
     *
     * @return
     * @author caoxin
     * @date 2019/4/3 9:10
     * @version 0.1
     * @since 2019/4/3 9:10
     */

    private List<BkkpDtlInf> getBkkpDtlInfList(List<LoanAccNoVo> loanAccNos, List<BigDecimal> amountSummary) {
        // 记账明细信息list
        List<BkkpDtlInf> bkkpDtlInfList = new ArrayList<>();
        // 生成非西安春和记账明细List
        generatorNotXiAnBkkpDtlInfList(amountSummary, loanAccNos, bkkpDtlInfList);
        // 生成西安春和记账明细List
        generatorXiAnBkkpDtlInfList(amountSummary, loanAccNos, bkkpDtlInfList);

        return bkkpDtlInfList;
    }

    /**
     * 生成非西安春和记账明细List依据需求: <br>
     *
     * 0.1:caoxin:2019/4/3 15:58: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/3 15:58
     * @date 2019/4/3 15:58
     * @version 0.1
     */

    private void generatorNotXiAnBkkpDtlInfList(List<BigDecimal> amountSummary, List<LoanAccNoVo> loanAccNos, List<BkkpDtlInf> bkkpDtlInfList) {
        for (LoanAccNoVo loanAccNo : loanAccNos) {
            BkkpDtlInf bkkpDtlInf = new BkkpDtlInf();
            setBaseBkkpDtlInf(bkkpDtlInf, loanAccNo);
            if ("B".equals(loanAccNo.getAcconutType())) {// 12DL个人百度中长期联合贷款
                // 中长期正常本金余额
                bkkpDtlInf.setTransAmt(amountSummary.get(0));
                // 借贷标记（贷）
                bkkpDtlInf.setDbLndFlg(loanAccNo.getDcDlag());
                // 财务套号
                bkkpDtlInf.setAcctSetNo("1");
                bkkpDtlInfList.add(bkkpDtlInf);
            } else if ("C".equals(loanAccNo.getAcconutType())) {   // 12DK个人百度短期联合贷款
                // 短期正常本金余额
                bkkpDtlInf.setTransAmt(amountSummary.get(1));
                // 借贷标记（贷）
                bkkpDtlInf.setDbLndFlg(loanAccNo.getDcDlag());
                // 财务套号
                bkkpDtlInf.setAcctSetNo("2");
                bkkpDtlInfList.add(bkkpDtlInf);
            } else if ("D".equals(loanAccNo.getAcconutType())) { // 12DM个人逾期百度联合贷款
                // 逾期本金余额
                bkkpDtlInf.setTransAmt(amountSummary.get(2));
                // 借贷标记（贷）
                bkkpDtlInf.setDbLndFlg(loanAccNo.getDcDlag());
                // 财务套号
                bkkpDtlInf.setAcctSetNo("3");
                bkkpDtlInfList.add(bkkpDtlInf);
            } else if ("E".equals(loanAccNo.getAcconutType())) {// 13AJ个人百度联合贷款应收利息
                // 代偿利息
                bkkpDtlInf.setTransAmt(amountSummary.get(3));
                // 借贷标记（付）
                bkkpDtlInf.setDbLndFlg(loanAccNo.getDcDlag());
                // 财务套号
                bkkpDtlInf.setAcctSetNo("4");
                bkkpDtlInfList.add(bkkpDtlInf);
            } else if ("F".equals(loanAccNo.getAcconutType())) {
                // 50CH个人百度联合贷款利息收入
                bkkpDtlInf.setTransAmt(amountSummary.get(4));// 代偿罚息
                bkkpDtlInf.setDbLndFlg(loanAccNo.getDcDlag());// 借贷标记（付）
                bkkpDtlInf.setAcctSetNo("5");// 财务套号
                bkkpDtlInfList.add(bkkpDtlInf);
            } else if ("G".equals(loanAccNo.getAcconutType())) {  // 714个人百度联合贷款应收未收利息
                bkkpDtlInf.setTransAmt(amountSummary.get(4));// 代偿罚息
                bkkpDtlInf.setDbLndFlg(loanAccNo.getDcDlag());// 借贷标记（付）
                bkkpDtlInf.setAcctSetNo("6");// 财务套号
                bkkpDtlInfList.add(bkkpDtlInf);
            }
        }
    }

    /**
     * 生成西安春和记账明细List: <br>
     *
     * 0.1:caoxin:2019/4/3 15:59: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/3 15:59
     * @date 2019/4/3 15:59
     * @version 0.1
     */

    private void generatorXiAnBkkpDtlInfList(List<BigDecimal> amountSummary, List<LoanAccNoVo> loanAccNos, List<BkkpDtlInf> bkkpDtlInfList) {
        for (LoanAccNoVo loanAccNo : loanAccNos) {
            if ("A".equals(loanAccNo.getAcconutType())) {
                for (int i = 0; i < Integer.parseInt(loanAccNo.getAccountSize()); i++) {
                    BkkpDtlInf bkkpDtlInf = new BkkpDtlInf();
                    setBaseBkkpDtlInf(bkkpDtlInf, loanAccNo);
                    // 交易金额
                    bkkpDtlInf.setTransAmt(amountSummary.get(i));
                    // 借贷标记（借）
                    bkkpDtlInf.setDbLndFlg(loanAccNo.getDcDlag());
                    // 财务套号
                    bkkpDtlInf.setAcctSetNo(String.valueOf(i + 1));
                    bkkpDtlInfList.add(bkkpDtlInf);
                }
            }
        }
    }
    /**
     * 设置ReqCompensationBean基础信息: <br>
     *
     * 0.1:caoxin:2019/4/3 15:59: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/3 15:59
     * @date 2019/4/3 15:59
     * @version 0.1
     */

    private void setReqCompensationBeanInfo(ReqCompensationBean reqCompensationBean,String batchDate) throws Exception {
        // 前置系统编号
        reqCompensationBean.setPrevSysNo(BAIDUCOMPENSATION);
        // 设置前置日期
        reqCompensationBean.setPrevDt(batchDate.replace("-",""));
        // 设置前置流水号
        reqCompensationBean.setPrevFlowNo(generatorPreSerialNumber());
        // 设置业务代码
        reqCompensationBean.setBizCd(BAIDUCOMPENSATION);
        // 币种
        reqCompensationBean.setCurrCd("156");
        // 摘要码
        reqCompensationBean.setSmyCd("BR");
        // 是否检验户名，默认检验为0
        reqCompensationBean.setVerfAcctNmFlg("1");
    }
    /**
     * 设置记账明细的基本信息: <br>
     *
     * 0.1:caoxin:2019/4/3 15:59: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/3 15:59
     * @date 2019/4/3 15:59
     * @version 0.1
     */

    private void setBaseBkkpDtlInf(BkkpDtlInf bkkpDtlInf, LoanAccNoVo loanAccNo) {
        // 账号
        bkkpDtlInf.setAcctNo(loanAccNo.getAccountNo());
        // 账号名称
        bkkpDtlInf.setAcctNm(loanAccNo.getAccountName());
        // 摘要码
        bkkpDtlInf.setSmyCd("BR");
    }

    /**
     * 计算分录笔数,单边笔数，一借一贷，算两笔: <br>
     *
     * 0.1:caoxin:2019/4/3 16:00: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/3 16:00
     * @date 2019/4/3 16:00
     * @version 0.1
     */

    private String getEntrCnt(List<LoanAccNoVo> loanAccNos) {
        int count = 0;
        for (LoanAccNoVo loanAccNo : loanAccNos) {
            count += Integer.parseInt(loanAccNo.getAccountSize());
        }
        return String.valueOf(count);
    }
    /**
     * 获取西安春和保证金账户: <br>
     *
     * 0.1:caoxin:2019/4/3 16:00: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/3 16:00
     * @date 2019/4/3 16:00
     * @version 0.1
     */

    private String getXiAnMarginAccount(List<LoanAccNoVo> loanAccNos) {
        for (LoanAccNoVo loanAccNo : loanAccNos) {
            if ("A".equals(loanAccNo.getAcconutType())) {
                return loanAccNo.getAccountNo();
            }
        }
        return null;
    }


    /**
     * 生成前置流水号: <br>
     * <p>
     * 0.1:caoxin:2019/4/2 16:37: TODO: <br>
     *
     * @return
     * @author caoxin
     * 示例
     * 20030001904080000001
     * 20030001904080000002
     * 20030001904080000003
     * 20030001904080000004
     * @date 2019/4/2 16:37
     * @version 0.1
     * @since 2019/4/2 16:37
     */
    public String generatorPreSerialNumber() throws Exception {
        SequenceService sequenceService = (SequenceService) SpringContextUtils.getBean("dbSeqService");
        String serialNumber = sequenceService.getSequence(PRE_SERIAL_NUMBER, null, null);
        return INTERNET_LOAN_SYSTEM_NUMBER + DateUtility.formatDate(new Date(),"yyMMdd") + serialNumber;
    }
    /**
     *
     * 校验百度代偿总账、明细文件是否存在 <br>
     * 0.1:ludayong:2019年3月25日 下午4:45:24:新增 <br>
     *
     * @author ludayong
     * @since 2019年3月25日 下午4:45:24
     * @date 2019年3月25日 下午4:45:24
     * @version 0.1
     */
    public boolean sendCompensationFileErrorMsg(String baiduJyPath, String prdInfo) {
        boolean result = true;
        // 百度代偿明细文件
        boolean compensationItemFile = checkCompensationFileIsExit(baiduJyPath + File.separator + compensationItem);
        // 百度代偿总账文件
        boolean compensationLedgerFile = checkCompensationFileIsExit(baiduJyPath + File.separator + compensationLedger);
        // 解密文件失败，则告警
        String msgFile = "";
        if (!compensationItemFile) {
            msgFile = "代偿文件明细文件不存在";
        }
        if (!compensationLedgerFile) {
            if (!"".equals(msgFile)) {
                msgFile += "、代偿文件总账文件不存在";
            } else {
                msgFile += "代偿文件总账文件不存在";
            }
        }
        if (!"".equals(msgFile)) {
            result = false;
            if ("Enjoy".equals(prdInfo)) {
                msgFile = "尊享贷" + msgFile;
            } else if ("Manyi".equals(prdInfo)) {
                msgFile = "满易贷" + msgFile;
            }
            ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
            reqAlarmJudgementBean.setAlrmInf(msgFile);
            try {
                getrespAlarmJudgementBean(reqAlarmJudgementBean);
            } catch (Exception alarme) {
                alarme.printStackTrace();
                logger.debug("调用告警接口异常！" + alarme.getMessage());
            }
        }
        return result;
    }
    /**
     *
     * 校验百度代偿总账、明细文件是否存在 <br>
     * 0.1:ludayong:2019年3月25日 下午4:45:24:新增 <br>
     *
     * @author ludayong
     * @since 2019年3月25日 下午4:45:24
     * @date 2019年3月25日 下午4:45:24
     * @version 0.1
     */
    private boolean checkCompensationFileIsExit(String compensationFilePath) {
        File compensationFile = new File(compensationFilePath);
        if (compensationFile.exists()) {
            return true;
        }
        return false;
    }
    @Override
    public boolean receiveCompensationFile() throws Exception {
        return false;
    }
	/**
	 * 
	 * 校验跑批批次日期是否为空 <br>
	 * 0.1:ludayong:2019年5月8日 上午9:02:57:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年5月8日 上午9:02:57
	 * @date 2019年5月8日 上午9:02:57
	 * @version 0.1
	 */
	public boolean checkBatchDateIsNullorBlank(String batchDate, String batchName) {
		// 跑批批次日期不为空时，返回false
		boolean result = false;
		if (StringUtil.isNullorBank(batchDate)) {
			// 跑批批次日期为空时，返回true
			result = true;
			// 告警信息
			String alrmInf = "入参：跑批批次日期为空！";
			// 告警判断接口请求bean
			ReqAlarmJudgementBean reqAlarmJudgementBean = new ReqAlarmJudgementBean();
			// 告警信息
			reqAlarmJudgementBean.setAlrmInf(batchName + alrmInf);
			try {
				// 调用的告警服务
				getrespAlarmJudgementBean(reqAlarmJudgementBean);
			} catch (Exception alarme) {
				alarme.printStackTrace();
				logger.error("调用告警接口异常！" + alarme.getMessage());
			}
		}
		return result;
	}

}
